<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace notify\controllers;

use extend\weixin\WxConf;

/**
 * 默认
 * @auther clevstn
 * @since 2.0
 * @datetime 2023.11.22 11:31
 */
class SiteController extends BaseController
{
    /**
     * 微信消息推送服务 - 消息签名token串 - 回传验证
     * @return string
     */
    public function actionIndex()
    {
        $signature = $_GET["signature"] ?? '';
        $timestamp = $_GET["timestamp"] ?? '';
        $nonce = $_GET["nonce"] ?? '';

        $token = WxConf::NOTIFY_TOKEN;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if ($tmpStr == $signature ) {
            return $_GET['echostr'];
        } else {
            return 'Failure';
        }
    }
}